package com.itheima.info.system.manager.dao;

import com.itheima.info.system.manager.domain.Student;

import java.util.ArrayList;

public class StudentDao implements IBaseStudentDao {
    private ArrayList<Student> students = new ArrayList<>();


    @Override
    public void add(Student student) {
        students.add(student);
    }

    @Override
    public void delete(String sid) {
        int index = getIndexBySid(sid);
        students.remove(index);
    }

    @Override
    public void updata(String sid, Student student) {
        int index = getIndexBySid(sid);
        students.set(index, student);
    }

    @Override
    public ArrayList<Student> findAll() {
        return students;
    }

    @Override
    public int getIndexBySid(String sid) {
        int index = -1;
        for (int i = 0; i < students.size(); i++) {
            if (sid.equals(students.get(i).getSid())) {
                index = i;
            }
        }
        return index;
    }

}
